package com.cwj.timingTask;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * @author chenwujie
 * @date 2020/11/049:25
 */
public class MyScheduler {
    public static void main(String[] args) throws SchedulerException {
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();

        JobDetail job1 = JobBuilder.newJob(MyTask.class).withDescription("job1").build();

        Date startDate = new Date();

        Date endDate = new Date();
        endDate.setTime(startDate.getTime() + 1000 * 60 * 5);
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "triggerGroup1")
                .usingJobData("trigger1", "这是jobDetail1的trigger")
                .startAt(startDate)
                .endAt(endDate)
                .withSchedule(CronScheduleBuilder.cronSchedule("0/1 * * * * ?"))
                .build();

        scheduler.scheduleJob(job1, cronTrigger);
        System.out.println("任务开始---》");
        scheduler.start();
        System.out.println("任务结束----");

    }
}
